<%@ Page Language="C#" Theme="Defaultsys" EnableEventValidation="false" AutoEventWireup="true"
    CodeFile="Contact.aspx.cs" Inherits="Contact" Title="Rapport Plan System - Contact"
    MasterPageFile="~/MasterPage.master" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<asp:Content runat="server" ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1">
  <link rel="stylesheet" type="text/css" media="all" href="jscripts/date/calendar-tas.css" title="win2k-cold-1" />
  

    <script type="text/javascript" src="jscripts/date/calendar.js"></script>

    <script type="text/javascript" src="jscripts/date/calendar-setup.js"></script>

    <script type="text/javascript" language="javascript">
        function ContactTypeChange(obj)
        {
       
            var divAttender = document.getElementById("divAttender");
            var divBuyer = document.getElementById("divBuyer");
            var divClient = document.getElementById("divClient");
            var divDefendant = document.getElementById("divDefendant");
            var cmb = document.getElementById("ctl00_ContentPlaceHolder1_cmbContactType");
               
            
            switch (cmb[cmb.selectedIndex].value)
            {
                case "Attender":
                    divAttender.style.display = "inline";
                    divBuyer.style.display = "none";
                    divClient.style.display = "none";
                    divDefendant.style.display = "none";
                    break;
                case "Buyer":
                    divAttender.style.display = "none";
                    divBuyer.style.display = "inline";
                    divClient.style.display = "none";
                    divDefendant.style.display = "none";
                    break;
                case "Client":
                    divAttender.style.display = "none";
                    divBuyer.style.display = "none";
                    divClient.style.display = "inline";
                    divDefendant.style.display = "none";
                    break;
                case "Defendant":
                    divAttender.style.display = "none";
                    divBuyer.style.display = "none";
                    divClient.style.display = "none";
                    divDefendant.style.display = "inline";
                    break;
            }
           }
                      
        var arrInput = new Array(0);
        var arrInputValue = new Array(0);

        function addInput() {
         
        for (intI=0;intI<arrInput.length;intI++) {
            arrInputValue[intI]=document.getElementById("test"+ arrInput[intI]).value;
        }     
        
        arrInput.push(arrInput.length);
        arrInputValue.push("");
        display();
        return false;
        }

       function display() {
            document.getElementById('parah').innerHTML="";
            for (intI=0;intI<arrInput.length;intI++) {
            alert(document.getElementById('parah').innerHTML);
            document.getElementById('parah').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
            }
            alert(document.getElementById('parah').innerHTML);
            
        }
        

        function saveValue(intId,strValue) {
        arrInputValue[intId]=strValue;
        }  

        function createInput(id,value) {        
        return "<input type=\"file\" id=\"test"+ id +"\" value=\""+ value +"\"><br>";
        }

        function deleteInput() {
        if (arrInput.length > 0) { 
         arrInput.pop(); 
         arrInputValue.pop();
        }
        display(); 
        return false;
        }

          //attachments
      var fileNo=1;
      function AddAttachmentControls()
			{
				var tableAttachFiles = document.getElementById( "ctl00_ContentPlaceHolder1_tableAttachFiles" ).tBodies[0];
				var newelem = document.createElement("TR");
				newelem.id = "trAttachFile";
				newelem.width="100%";
				var newelem2 = document.createElement("TD");
				newelem2.width = 75;
				newelem2.id = "tdFileNo";
				//newelem2.innerHTML = "File " + ( document.getElementsByName("ctl00_ContentPlaceHolder1_AttachFile").length + 1) + ":";
				fileNo+=1;
				newelem2.innerHTML = "File " + fileNo + ":";
				newelem.appendChild( newelem2 );
				newelem2 = document.createElement("TD");
				var newelem3 = document.createElement("INPUT");
				newelem3.name = "AttachFile";
				newelem3.id = "AttachFile";
				newelem3.type = "file";
				newelem3.style.width = "550";
				newelem3.size = "100";
				newelem2.appendChild( newelem3 );
				newelem.appendChild( newelem2 );
				tableAttachFiles.appendChild(newelem);
				return false;
			}
			
			function UpdateFilesNo()
			{
				var tdFileNo = document.getElementsByName( "tdFileNo" );
				var index;
				//alert( tdFileNo.length );
				for ( index = 0; index < tdFileNo.length; index ++ )
				{
					tdFileNo[ index ].innerHTML = "File " + ( index + 1 ) + ":";
				}
			}
			
			function Save_Discard()
			{
			    document.getElementById("ctl00_ContentPlaceHolder1_hidSaveChanges").value = confirm("Save changes?");
			    SaveCombosValues();
			}	

            function ValidateState(oSrc, args)
		    {		        
		        var objCountry = document.getElementById('ctl00_ContentPlaceHolder1_cmbCountry');
		        var objStates = document.getElementById('ctl00_ContentPlaceHolder1_cmbStates');
		        args.IsValid = true;           
                if (objCountry.value == "United States" && objStates.value == "Choose a state...")
                    args.IsValid = false;
            }	

    </script>

    <table border="0" width="100%" cellpadding="0" cellspacing="0">
        <tr>
            <td class="contTable">
                <table width="60%">
                    <tr>
                        <td width="25%">
                            Contact type:
                        </td>
                        <td>
                            <asp:DropDownList ID="cmbContactTypes" runat="server" OnSelectedIndexChanged="LoadFieldsForContactType"
                                AutoPostBack="true" Width="60%">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Name:</td>
                        <td>
                            <asp:TextBox ID="txtName" runat="server" Width="60%"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtName"
                                CssClass="error" ErrorMessage="(*)Name is required" SetFocusOnError="True" Display="Dynamic">*</asp:RequiredFieldValidator>
                            <asp:CustomValidator ID="validateName" runat="server" ControlToValidate="txtName"
                                ErrorMessage="(*)A contact with this name already exists" OnServerValidate="validateName_ServerValidate">*</asp:CustomValidator></td>
                    </tr>
                    <tr>
                        <td>
                            Email address:</td>
                        <td>
                            <asp:TextBox ID="txtMail" runat="server" Width="60%"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="txtMail"
                                CssClass="error" ErrorMessage="(*)Email is required" SetFocusOnError="True" Display="Dynamic">*</asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="(*)Incorrect e-mail address"
                                ControlToValidate="txtMail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                                Display="Dynamic">*</asp:RegularExpressionValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Phone no.:</td>
                        <td>
                            <asp:TextBox ID="txtPhone" runat="server" Width="60%"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtPhone"
                                CssClass="error" ErrorMessage="(*)Phone is required" SetFocusOnError="True" Display="Dynamic">*</asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Mobile phone no:</td>
                        <td>
                            <asp:TextBox ID="txtMobile" runat="server" Width="60%"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtMobile"
                                CssClass="error" ErrorMessage="(*)Mobile phone is required" SetFocusOnError="True"
                                Display="Dynamic">*</asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Fax:</td>
                        <td>
                            <asp:TextBox ID="txtFax" runat="server" Width="60%"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td valign="top">
                            Mail address:</td>
                        <td>
                            <asp:TextBox ID="txtMailAddress" runat="server" TextMode="MultiLine" Width="60%"
                                Height="50"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtMailAddress"
                                CssClass="error" ErrorMessage="(*)Mail address is required" SetFocusOnError="True"
                                Display="Dynamic">*</asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            Mail city:</td>
                        <td>
                            <asp:TextBox ID="txtMailCity" runat="server" Width="60%"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtMailCity"
                                CssClass="error" ErrorMessage="(*)Mail city is required" SetFocusOnError="True"
                                Display="Dynamic">*</asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            Mail state:</td>
                        <td>
                            <asp:DropDownList ID="cmbStates" runat="server" Width="60%">
                            </asp:DropDownList>
                            <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="ValidateState"
                                ControlToValidate="cmbStates" ErrorMessage="(*)No state is selected">*</asp:CustomValidator></td>
                    </tr>
                    <tr>
                        <td valign="top">
                            Mail country:</td>
                        <td>
                            <asp:DropDownList ID="cmbCountry" runat="server" Width="60%">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            Mail zip:</td>
                        <td>
                            <asp:TextBox ID="txtZip" runat="server" Width="60%"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td valign="top">
                            Visit date:</td>
                        <td>
                            <asp:TextBox ID="txtVisitDate" runat="server"></asp:TextBox>
                            <img alt="calendar" src="jscripts/date/calendar.gif" id="f_trigger_from" style="cursor: pointer;"
                                border="0" />&nbsp;&nbsp;
                            <asp:Label ID="lblWrongFormatStar" runat="server" CssClass="error" ForeColor="Red"
                                Text="*" Visible="False"></asp:Label></td>                       
                    </tr>
                    <tr>
                        <td valign="top">
                            Active</td>
                        <td>
                            <asp:CheckBox ID="ckActive" runat="server" Checked="True" /></td>
                    </tr>
                    <tr>
                        <td valign="top">
                            Receive newsletters:</td>
                        <td>
                            <asp:CheckBox ID="ckReceiveNewsLetter" runat="server" Checked="True" /></td>
                    </tr>
                </table>
                <br />
                <asp:GridView ID="grdFields" GridLines="None" SkinID="gvGridNone" runat="server"
                    AutoGenerateColumns="false" ShowHeader="false" Width="60%" BorderStyle="none">
                    <Columns>
                        <asp:BoundField HeaderText="Property" DataField="Name" SortExpression="Name" ItemStyle-Width="25%"
                            ItemStyle-VerticalAlign="Top" ItemStyle-BorderStyle="none" />
                        <asp:BoundField HeaderText="Type" DataField="Type" SortExpression="Type" />
                        <asp:TemplateField HeaderText="Id" Visible="false">
                            <ItemTemplate>
                                <asp:TextBox ID="id" runat="server" Visible="false" Text='<%# Eval("ContactPageFieldId") %>'></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <br />
                
                

                <asp:GridView ID="grdContactGroups" SkinID="gvGrid" runat="server" AutoGenerateColumns="false"
                    OnRowCommand="Command" Width="100%" OnRowDataBound="RowDataBound" AllowPaging="true"
                    OnPageIndexChanging="grdContactGroups_PageIndexChanging" Visible="false">
                    <Columns>
                        <asp:TemplateField HeaderText="ID" ItemStyle-HorizontalAlign="Right" HeaderStyle-Width="3%">
                            <ItemTemplate>
                                <%# Container.DataItemIndex + 1 %>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField HeaderText="Contact group" DataField="Name" SortExpression="Name"
                            HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="50%" />
                        <asp:TemplateField HeaderText="Edit">
                            <ItemTemplate>
                                <asp:Button ID="btnEdit" runat="server" Text="Edit" CommandArgument='<%# Eval("ContactGroupId") %>' />
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" Width="10%" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Remove">
                            <ItemTemplate>
                                <asp:Button ID="btnRemove" runat="server" Text="Remove" CommandArgument='<%# Eval("ContactGroupId") %>' />
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" Width="10%" />
                        </asp:TemplateField>
                    </Columns>
                    <EmptyDataTemplate>
                        The contact does not belong to any contact group.</EmptyDataTemplate>
                    <PagerStyle VerticalAlign="Middle" HorizontalAlign="Left" Wrap="False" CssClass="paging"
                        Font-Bold="True"></PagerStyle>
                    <PagerSettings Mode="NumericFirstLast" />
                </asp:GridView>
                <br />
                
                
                <asp:GridView ID="grdContactFiles" GridLines="None" Width="200px" SkinID="gvGridNone"
                    runat="server" AutoGenerateColumns="false" OnRowCommand="ContactFileCommand">
                    <Columns>
                        <asp:TemplateField HeaderText="File path">
                            <ItemTemplate>
                                <asp:HyperLink ID="linkFile" runat="server" Target="_blank"  NavigateUrl='<%# Eval("FileURL")%>'><%# Eval("File")%></asp:HyperLink>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Remove">
                            <ItemTemplate>
                                <asp:Button ID="btnRemove" runat="server" Text="Remove" CommandArgument='<%# Eval("ContactFileId") %>' />
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Id" Visible="false">
                            <ItemTemplate>
                                <asp:TextBox ID="id" runat="server" Visible="false" Text='<%# Eval("ContactFileId") %>'></asp:TextBox>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <table border="0">
                    <tr>
                        <td colspan="2" align="center">
                            <asp:Button ID="btnAddFiles" runat="server" Text="Add more files" />
                        </td>
                    </tr>
                    <tr>
                        <td id="parah">
                        </td>
                    </tr>
                </table>
                
                <table width="100%">
                <tr>
                <td>
                    <table id="tableAttachFiles" width="100%" runat="server" align="left" border="0">
                    <tr id="trAttachFile" width="100%">
                        <td id="tdFileNo" width="93">
                            File 1:</td>
                        <td width="50" align="left">
                            <input id="AttachFile" size="100" style="width: 550px" type="file" name="AttachFile"
                                runat="server" />
                        </td>
                    </tr>                     
                </table>
                </td>
                <tr>
                <td>
                <table border="0" width="100%" cellpadding="0" cellspacing="0">
                   <tr>
                        <td>
                            <asp:Button ID="Button1" runat="server" OnClick="Save" Text="Save" />
                            <asp:Button ID="Button2" runat="server" OnClick="Cancel" Text="Cancel" CausesValidation="false" /></td>
                    </tr>
                </table>
                    <asp:Label ID="lblSavedContact" runat="server" ForeColor="#FF8000" Text="The contact was saved succesfully"
                        Visible="False"></asp:Label></td>
                </tr>
                </table>
                

                <script type="text/javascript">
        Calendar.setup({
            inputField     :    "ctl00_ContentPlaceHolder1_txtVisitDate",     // id of the input field
            ifFormat       :    "%m/%d/%Y",    // format of the input field
            button         :    "f_trigger_from",  // trigger for the calendar (button ID)
            singleClick    :    true
        });
        
      for (i=0; i<=9; i++){
        if (document.getElementById("ctl00_ContentPlaceHolder1_grdFields_ctl0"+i+"_txtDateTimeId")!= null){
        Calendar.setup({
            inputField     :    "ctl00_ContentPlaceHolder1_grdFields_ctl0"+i+"_txtDateTimeId",     // id of the input field
            ifFormat       :    "%m/%d/%Y",    // format of the input field
            button         :    "ctl00_ContentPlaceHolder1_grdFields_ctl0"+i+"_dateId",  // trigger for the calendar (button ID)
            singleClick    :    true
        });
        }
      }
        
                </script>

                <asp:ValidationSummary runat="server" ID="vs" DisplayMode="List" />
                &nbsp;&nbsp;<br />
                <asp:Label ID="lblWrongFormat" runat="server" CssClass="error" ForeColor="Red" Text="(*)Date has wrong format or was not entered"
                    Visible="False"></asp:Label><br />
                <asp:Label ID="lblFileExist" runat="server" ForeColor="Red" Text="File does not exist!"
                    Visible="False" Width="285px"></asp:Label><br />
            </td>
        </tr>
    </table>
</asp:Content>
